﻿namespace WMS6.Web.UserControls
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Drawing;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BaseInfoDetailServiceRef;
    using WMS6.Web.CommonMethodServiceRef;

    public class LotAtrributeCtrl : UserControl
    {
        private int columnCount;
        private string controlID;
        private bool enabled = true;
        protected Literal Literal1;
        private string owerid;
        private bool shelflifeIndicator = false;
        private string skuid;
        protected HtmlGenericControl test;

        public void ClearControl()
        {
            this.test.Controls.Clear();
        }

        private int ConvertType2Int(string type)
        {
            int retInt = 0;
            string CS40001 = type.ToUpper();
            if (CS40001 == null)
            {
                return retInt;
            }
            if (!(CS40001 == "CHAR"))
            {
                if (CS40001 != "DATE")
                {
                    if (CS40001 != "NUMBER")
                    {
                        return retInt;
                    }
                    return 3;
                }
            }
            else
            {
                return 1;
            }
            return 2;
        }

        private CompareValidator GetCompareValidator(string ctrl, string type)
        {
            int temp = this.ConvertType2Int(type);
            CompareValidator comp = null;
            if (temp != 0)
            {
                comp = new CompareValidator {
                    ControlToValidate = ctrl,
                    Operator = ValidationCompareOperator.DataTypeCheck,
                    Display = ValidatorDisplay.Dynamic,
                    ForeColor = Color.Red
                };
                switch (temp)
                {
                    case 1:
                        comp.Type = ValidationDataType.String;
                        comp.ErrorMessage = "Must be  Char";
                        return comp;

                    case 2:
                        comp.Type = ValidationDataType.String;
                        comp.ErrorMessage = "Must be Date";
                        return comp;
                }
                comp.Type = ValidationDataType.Double;
                comp.ErrorMessage = "Must be Number";
            }
            return comp;
        }

        private Control GetControlByTypeAndValue(string type, string value, string isMandatory)
        {
            Control ctrl = null;
            string CS40001 = type.ToUpper();
            if ((CS40001 != null) && (CS40001 == "OPTIONLIST"))
            {
                ctrl = new DropDownList();
                List<WMS6.Web.CommonMethodServiceRef.LotAttributeCodeInfo> LotAttributeCode = CommoneMethodServiceClientProxy.GetInstance().GetLotAttributCodeByGroupID(value);
                if ((LotAttributeCode != null) && (LotAttributeCode.Count > 0))
                {
                    ((DropDownList) ctrl).DataSource = LotAttributeCode;
                    ((DropDownList) ctrl).DataTextField = "DESCR";
                    ((DropDownList) ctrl).DataValueField = "CODEID";
                    ((DropDownList) ctrl).DataBind();
                    ((DropDownList) ctrl).Enabled = this.Enabled;
                    if (!(string.IsNullOrEmpty(isMandatory) || !(isMandatory.ToUpper() == "N")))
                    {
                        ((DropDownList) ctrl).Items.Insert(0, "");
                    }
                }
                ((DropDownList) ctrl).CssClass = "mediumselectbox";
                return ctrl;
            }
            ctrl = new TextBox();
            ((TextBox) ctrl).Text = value;
            ((TextBox) ctrl).CssClass = "textbox";
            ((TextBox) ctrl).Enabled = this.Enabled;
            return ctrl;
        }

        private RequiredFieldValidator GetRequirField(string ctrl)
        {
            return new RequiredFieldValidator { ControlToValidate = ctrl, ErrorMessage = "*", Display = ValidatorDisplay.Dynamic, ForeColor = Color.Red };
        }

        public void LoadData(string skuID, string ownerID, string contrlID, bool flage, int columnCount)
        {
            List<Control> controls = new List<Control>();
            LotTemplateInfo lotTemplate = CommoneMethodServiceClientProxy.GetInstance().GetLotTemplateInfo(skuID, ownerID);
            int intCount = 0;
            Table tb = new Table();
            if (lotTemplate != null)
            {
                int i;
                DataTable table = new DataTable();
                table.Columns.Add("keys", typeof(string));
                table.Columns.Add("values", typeof(int));
                if (lotTemplate.LotAttr01Visible == "Y")
                {
                    table.Rows.Add(new object[] { "LotAttribut01", lotTemplate.LotAttr01Seqno });
                }
                if (lotTemplate.LotAttr02Visible == "Y")
                {
                    table.Rows.Add(new object[] { "LotAttribut02", lotTemplate.LotAttr02Seqno });
                }
                if (lotTemplate.LotAttr03Visible == "Y")
                {
                    table.Rows.Add(new object[] { "LotAttribut03", lotTemplate.LotAttr03Seqno });
                }
                if (lotTemplate.LotAttr04Visible == "Y")
                {
                    table.Rows.Add(new object[] { "LotAttribut04", lotTemplate.LotAttr04Seqno });
                }
                if (lotTemplate.LotAttr05Visible == "Y")
                {
                    table.Rows.Add(new object[] { "LotAttribut05", lotTemplate.LotAttr05Seqno });
                }
                if (lotTemplate.LotAttr06Visible == "Y")
                {
                    table.Rows.Add(new object[] { "LotAttribut06", lotTemplate.LotAttr06Seqno });
                }
                if (lotTemplate.LotAttr07Visible == "Y")
                {
                    table.Rows.Add(new object[] { "LotAttribut07", lotTemplate.LotAttr07Seqno });
                }
                if (lotTemplate.LotAttr08Visible == "Y")
                {
                    table.Rows.Add(new object[] { "LotAttribut08", lotTemplate.LotAttr08Seqno });
                }
                if (lotTemplate.LotAttr09Visible == "Y")
                {
                    table.Rows.Add(new object[] { "LotAttribut09", lotTemplate.LotAttr09Seqno });
                }
                if (lotTemplate.LotAttr10Visible == "Y")
                {
                    table.Rows.Add(new object[] { "LotAttribut10", lotTemplate.LotAttr10Seqno });
                }
                if (lotTemplate.ProduceDateVisible == "Y")
                {
                    table.Rows.Add(new object[] { "ProduceDate", lotTemplate.ProduceDateSeqno });
                }
                if (lotTemplate.ExpiryDateVisible == "Y")
                {
                    table.Rows.Add(new object[] { "ExpiryDate", lotTemplate.ExpiryDateSeqno });
                }
                if (lotTemplate.ExternalLotVisible == "Y")
                {
                    table.Rows.Add(new object[] { "ExternalLot", lotTemplate.ExternalLotSeqno });
                }
                table = new DataView(table) { Sort = "values ASC" }.ToTable();
                List<string> stringList = new List<string>();
                for (i = 0; i < table.Rows.Count; i++)
                {
                    stringList.Add(table.Rows[i]["keys"].ToString());
                }
                WMS6.Web.BaseInfoDetailServiceRef.SkuInfo skuInfo = null;
                if (this.ShelfLifeIndicator)
                {
                    skuInfo = BaseInfoDetailServiceClientProxy.GetInstance().GetDetailInfoByID(ownerID, skuID, "", "SKU") as WMS6.Web.BaseInfoDetailServiceRef.SkuInfo;
                }
                foreach (string tempStr in stringList)
                {
                    TableRow tr12;
                    TableCell tc1;
                    TableCell tc2;
                    Control ctrl10;
                    Label lblMustInput;
                    string temp;
                    RequiredFieldValidator requ;
                    CompareValidator comp;
                    switch (tempStr)
                    {
                        case "LotAttribut01":
                            if (!string.IsNullOrEmpty(lotTemplate.LotAttr01Visible) && (lotTemplate.LotAttr01Visible == "Y"))
                            {
                                TableRow tr1 = new TableRow();
                                tr12 = new TableRow();
                                tc1 = new TableCell();
                                Label lblLotAttribute1 = new Label {
                                    Text = lotTemplate.LotAttr01Label,
                                    CssClass = "label"
                                };
                                tc1.Controls.Add(lblLotAttribute1);
                                tc2 = new TableCell();
                                Control ctrl1 = this.GetControlByTypeAndValue(lotTemplate.LotAttr01Type, lotTemplate.LotAttr01Value, lotTemplate.LotAttr01Mandatory);
                                ctrl1.ID = "ctrl1";
                                tc2.Controls.Add(ctrl1);
                                if (!string.IsNullOrEmpty(lotTemplate.LotAttr01Mandatory) && (lotTemplate.LotAttr01Mandatory == "Y"))
                                {
                                    ctrl10 = this.GetRequirField("ctrl1");
                                    ((RequiredFieldValidator) ctrl10).ErrorMessage = "请输入  " + lotTemplate.LotAttr01Label;
                                    tc2.Controls.Add(ctrl10);
                                    lblMustInput = new Label {
                                        Text = "*",
                                        ForeColor = Color.Red
                                    };
                                    tc1.Controls.Add(lblMustInput);
                                    if (!flage)
                                    {
                                        ((RequiredFieldValidator) ctrl10).Enabled = false;
                                        lblMustInput.Visible = false;
                                        lblLotAttribute1.ForeColor = Color.Red;
                                        if (lotTemplate.LotAttr01Type.ToUpper() == "OPTIONLIST")
                                        {
                                            ((DropDownList) ctrl1).Items.Insert(0, "");
                                        }
                                    }
                                }
                                Control ctrl11 = this.GetCompareValidator("ctrl1", lotTemplate.LotAttr01Type);
                                if (ctrl11 != null)
                                {
                                    tc2.Controls.Add(ctrl11);
                                }
                                intCount++;
                                tr1.Cells.Add(tc1);
                                tr12.Cells.Add(tc2);
                                tb.Rows.Add(tr1);
                                tb.Rows.Add(tr12);
                                tr12.Width = Unit.Pixel(360);
                                controls.Add(ctrl1);
                                this.test.Controls.Add(tb);
                            }
                            break;

                        case "LotAttribut02":
                            if (!string.IsNullOrEmpty(lotTemplate.LotAttr02Visible) && (lotTemplate.LotAttr02Visible == "Y"))
                            {
                                TableRow tr2 = new TableRow();
                                TableRow tr22 = new TableRow();
                                tc1 = new TableCell();
                                Label lblLotAttribute2 = new Label {
                                    Text = lotTemplate.LotAttr02Label,
                                    CssClass = "label"
                                };
                                tc1.Controls.Add(lblLotAttribute2);
                                tc2 = new TableCell();
                                Control ctrl2 = this.GetControlByTypeAndValue(lotTemplate.LotAttr02Type, lotTemplate.LotAttr02Value, lotTemplate.LotAttr02Mandatory);
                                ctrl2.ID = "ctrl2";
                                tc2.Controls.Add(ctrl2);
                                if (!string.IsNullOrEmpty(lotTemplate.LotAttr02Mandatory) && (lotTemplate.LotAttr02Mandatory == "Y"))
                                {
                                    Control ctrl20 = this.GetRequirField("ctrl2");
                                    ((RequiredFieldValidator) ctrl20).ErrorMessage = "请输入  " + lotTemplate.LotAttr02Label;
                                    tc2.Controls.Add(ctrl20);
                                    lblMustInput = new Label {
                                        Text = "*",
                                        ForeColor = Color.Red
                                    };
                                    tc1.Controls.Add(lblMustInput);
                                    if (!flage)
                                    {
                                        ((RequiredFieldValidator) ctrl20).Enabled = false;
                                        lblMustInput.Visible = false;
                                        lblLotAttribute2.ForeColor = Color.Red;
                                        if (lotTemplate.LotAttr02Type.ToUpper() == "OPTIONLIST")
                                        {
                                            ((DropDownList) ctrl2).Items.Insert(0, "");
                                        }
                                    }
                                }
                                Control ctrl21 = this.GetCompareValidator("ctrl2", lotTemplate.LotAttr02Type);
                                if (ctrl21 != null)
                                {
                                    tc2.Controls.Add(ctrl21);
                                }
                                tr2.Cells.Add(tc1);
                                tr22.Cells.Add(tc2);
                                tb.Rows.Add(tr2);
                                tb.Rows.Add(tr22);
                                tr22.Width = Unit.Pixel(360);
                                controls.Add(ctrl2);
                            }
                            break;

                        case "LotAttribut03":
                            if (!string.IsNullOrEmpty(lotTemplate.LotAttr03Visible) && (lotTemplate.LotAttr03Visible == "Y"))
                            {
                                TableRow tr3 = new TableRow();
                                TableRow tr32 = new TableRow();
                                tc1 = new TableCell();
                                Label lblLotAttribute3 = new Label {
                                    Text = lotTemplate.LotAttr03Label,
                                    CssClass = "label"
                                };
                                tc1.Controls.Add(lblLotAttribute3);
                                tc2 = new TableCell();
                                Control ctrl3 = this.GetControlByTypeAndValue(lotTemplate.LotAttr03Type, lotTemplate.LotAttr03Value, lotTemplate.LotAttr03Mandatory);
                                ctrl3.ID = "ctrl3";
                                tc2.Controls.Add(ctrl3);
                                if (!string.IsNullOrEmpty(lotTemplate.LotAttr03Mandatory) && (lotTemplate.LotAttr03Mandatory == "Y"))
                                {
                                    Control ctrl30 = this.GetRequirField("ctrl3");
                                    ((RequiredFieldValidator) ctrl30).ErrorMessage = "请输入  " + lotTemplate.LotAttr03Label;
                                    tc2.Controls.Add(ctrl30);
                                    lblMustInput = new Label {
                                        Text = "*",
                                        ForeColor = Color.Red
                                    };
                                    tc1.Controls.Add(lblMustInput);
                                    if (!flage)
                                    {
                                        ((RequiredFieldValidator) ctrl30).Enabled = false;
                                        lblMustInput.Visible = false;
                                        lblLotAttribute3.ForeColor = Color.Red;
                                        if (lotTemplate.LotAttr03Type.ToUpper() == "OPTIONLIST")
                                        {
                                            ((DropDownList) ctrl3).Items.Insert(0, "");
                                        }
                                    }
                                }
                                Control ctrl31 = this.GetCompareValidator("ctrl3", lotTemplate.LotAttr03Type);
                                if (ctrl31 != null)
                                {
                                    tc2.Controls.Add(ctrl31);
                                }
                                tr3.Cells.Add(tc1);
                                tr32.Cells.Add(tc2);
                                tb.Rows.Add(tr3);
                                tb.Rows.Add(tr32);
                                tr32.Width = Unit.Pixel(360);
                                controls.Add(ctrl3);
                            }
                            break;

                        case "LotAttribut04":
                            if (!string.IsNullOrEmpty(lotTemplate.LotAttr04Visible) && (lotTemplate.LotAttr04Visible == "Y"))
                            {
                                TableRow tr4 = new TableRow();
                                TableRow tr42 = new TableRow();
                                tc1 = new TableCell();
                                Label lblLotAttribute4 = new Label {
                                    Text = lotTemplate.LotAttr04Label,
                                    CssClass = "label"
                                };
                                tc1.Controls.Add(lblLotAttribute4);
                                tc2 = new TableCell();
                                Control ctrl4 = this.GetControlByTypeAndValue(lotTemplate.LotAttr04Type, lotTemplate.LotAttr04Value, lotTemplate.LotAttr04Mandatory);
                                ctrl4.ID = "ctrl4";
                                tc2.Controls.Add(ctrl4);
                                if (!string.IsNullOrEmpty(lotTemplate.LotAttr04Mandatory) && (lotTemplate.LotAttr04Mandatory == "Y"))
                                {
                                    Control ctrl40 = this.GetRequirField("ctrl4");
                                    ((RequiredFieldValidator) ctrl40).ErrorMessage = "请输入  " + lotTemplate.LotAttr04Label;
                                    tc2.Controls.Add(ctrl40);
                                    lblMustInput = new Label {
                                        Text = "*",
                                        ForeColor = Color.Red
                                    };
                                    tc1.Controls.Add(lblMustInput);
                                    if (!flage)
                                    {
                                        ((RequiredFieldValidator) ctrl40).Enabled = false;
                                        lblMustInput.Visible = false;
                                        lblLotAttribute4.ForeColor = Color.Red;
                                        if (lotTemplate.LotAttr04Type.ToUpper() == "OPTIONLIST")
                                        {
                                            ((DropDownList) ctrl4).Items.Insert(0, "");
                                        }
                                    }
                                }
                                Control ctr41 = this.GetCompareValidator("ctrl4", lotTemplate.LotAttr04Type);
                                if (ctr41 != null)
                                {
                                    tc2.Controls.Add(ctr41);
                                }
                                tr4.Cells.Add(tc1);
                                tr42.Cells.Add(tc2);
                                tb.Rows.Add(tr4);
                                tb.Rows.Add(tr42);
                                tr42.Width = Unit.Pixel(360);
                                controls.Add(ctrl4);
                            }
                            break;

                        case "LotAttribut05":
                            if (!string.IsNullOrEmpty(lotTemplate.LotAttr05Visible) && (lotTemplate.LotAttr05Visible == "Y"))
                            {
                                TableRow tr5 = new TableRow();
                                TableRow tr52 = new TableRow();
                                tc1 = new TableCell();
                                Label lblLotAttribute5 = new Label {
                                    Text = lotTemplate.LotAttr05Label,
                                    CssClass = "label"
                                };
                                tc1.Controls.Add(lblLotAttribute5);
                                tc2 = new TableCell();
                                Control ctrl5 = this.GetControlByTypeAndValue(lotTemplate.LotAttr05Type, lotTemplate.LotAttr05Value, lotTemplate.LotAttr05Mandatory);
                                ctrl5.ID = "ctrl5";
                                tc2.Controls.Add(ctrl5);
                                if (!string.IsNullOrEmpty(lotTemplate.LotAttr05Mandatory) && (lotTemplate.LotAttr05Mandatory == "Y"))
                                {
                                    Control ctrl50 = this.GetRequirField("ctrl5");
                                    ((RequiredFieldValidator) ctrl50).ErrorMessage = "请输入  " + lotTemplate.LotAttr05Label;
                                    tc2.Controls.Add(ctrl50);
                                    lblMustInput = new Label {
                                        Text = "*",
                                        ForeColor = Color.Red
                                    };
                                    tc1.Controls.Add(lblMustInput);
                                    if (!flage)
                                    {
                                        ((RequiredFieldValidator) ctrl50).Enabled = false;
                                        lblMustInput.Visible = false;
                                        lblLotAttribute5.ForeColor = Color.Red;
                                        if (lotTemplate.LotAttr05Type.ToUpper() == "OPTIONLIST")
                                        {
                                            ((DropDownList) ctrl5).Items.Insert(0, "");
                                        }
                                    }
                                }
                                Control ctr51 = this.GetCompareValidator("ctrl5", lotTemplate.LotAttr05Type);
                                if (ctr51 != null)
                                {
                                    tc2.Controls.Add(ctr51);
                                }
                                tr5.Cells.Add(tc1);
                                tr52.Cells.Add(tc2);
                                tb.Rows.Add(tr5);
                                tb.Rows.Add(tr52);
                                tr52.Width = Unit.Pixel(360);
                                controls.Add(ctrl5);
                            }
                            break;

                        case "LotAttribut06":
                            if (!string.IsNullOrEmpty(lotTemplate.LotAttr06Visible) && (lotTemplate.LotAttr06Visible == "Y"))
                            {
                                TableRow tr6 = new TableRow();
                                TableRow tr62 = new TableRow();
                                tc1 = new TableCell();
                                Label lblLotAttribute6 = new Label {
                                    Text = lotTemplate.LotAttr06Label,
                                    CssClass = "label"
                                };
                                tc1.Controls.Add(lblLotAttribute6);
                                tc2 = new TableCell();
                                Control ctrl6 = this.GetControlByTypeAndValue(lotTemplate.LotAttr06Type, lotTemplate.LotAttr06Value, lotTemplate.LotAttr06Mandatory);
                                ctrl6.ID = "ctrl6";
                                tc2.Controls.Add(ctrl6);
                                if (!string.IsNullOrEmpty(lotTemplate.LotAttr06Mandatory) && (lotTemplate.LotAttr06Mandatory == "Y"))
                                {
                                    Control ctrl60 = this.GetRequirField("ctrl6");
                                    ((RequiredFieldValidator) ctrl60).ErrorMessage = "请输入  " + lotTemplate.LotAttr06Label;
                                    tc2.Controls.Add(ctrl60);
                                    lblMustInput = new Label {
                                        Text = "*",
                                        ForeColor = Color.Red
                                    };
                                    tc1.Controls.Add(lblMustInput);
                                    if (!flage)
                                    {
                                        ((RequiredFieldValidator) ctrl60).Enabled = false;
                                        lblMustInput.Visible = false;
                                        lblLotAttribute6.ForeColor = Color.Red;
                                        if (lotTemplate.LotAttr06Type.ToUpper() == "OPTIONLIST")
                                        {
                                            ((DropDownList) ctrl6).Items.Insert(0, "");
                                        }
                                    }
                                }
                                Control ctr61 = this.GetCompareValidator("ctrl6", lotTemplate.LotAttr06Type);
                                if (ctr61 != null)
                                {
                                    tc2.Controls.Add(ctr61);
                                }
                                tr6.Cells.Add(tc1);
                                tr62.Cells.Add(tc2);
                                tb.Rows.Add(tr6);
                                tb.Rows.Add(tr62);
                                tr62.Width = Unit.Pixel(360);
                                controls.Add(ctrl6);
                            }
                            break;

                        case "LotAttribut07":
                            if (!string.IsNullOrEmpty(lotTemplate.LotAttr07Visible) && (lotTemplate.LotAttr07Visible == "Y"))
                            {
                                TableRow tr7 = new TableRow();
                                TableRow tr72 = new TableRow();
                                tc1 = new TableCell();
                                Label lblLotAttribute7 = new Label {
                                    Text = lotTemplate.LotAttr07Label,
                                    CssClass = "label"
                                };
                                tc1.Controls.Add(lblLotAttribute7);
                                tc2 = new TableCell();
                                Control ctrl7 = this.GetControlByTypeAndValue(lotTemplate.LotAttr07Type, lotTemplate.LotAttr07Value, lotTemplate.LotAttr07Mandatory);
                                ctrl7.ID = "ctrl7";
                                tc2.Controls.Add(ctrl7);
                                if (!string.IsNullOrEmpty(lotTemplate.LotAttr07Mandatory) && (lotTemplate.LotAttr07Mandatory == "Y"))
                                {
                                    Control ctrl70 = this.GetRequirField("ctrl7");
                                    ((RequiredFieldValidator) ctrl70).ErrorMessage = "请输入  " + lotTemplate.LotAttr07Label;
                                    tc2.Controls.Add(ctrl70);
                                    lblMustInput = new Label {
                                        Text = "*",
                                        ForeColor = Color.Red
                                    };
                                    tc1.Controls.Add(lblMustInput);
                                    if (!flage)
                                    {
                                        ((RequiredFieldValidator) ctrl70).Enabled = false;
                                        lblMustInput.Visible = false;
                                        lblLotAttribute7.ForeColor = Color.Red;
                                        if (lotTemplate.LotAttr07Type.ToUpper() == "OPTIONLIST")
                                        {
                                            ((DropDownList) ctrl7).Items.Insert(0, "");
                                        }
                                    }
                                }
                                Control ctr71 = this.GetCompareValidator("ctrl7", lotTemplate.LotAttr07Type);
                                if (ctr71 != null)
                                {
                                    tc2.Controls.Add(ctr71);
                                }
                                tr7.Cells.Add(tc1);
                                tr72.Cells.Add(tc2);
                                tb.Rows.Add(tr7);
                                tb.Rows.Add(tr72);
                                tr72.Width = Unit.Pixel(360);
                                controls.Add(ctrl7);
                            }
                            break;

                        case "LotAttribut08":
                            if (!string.IsNullOrEmpty(lotTemplate.LotAttr08Visible) && (lotTemplate.LotAttr08Visible == "Y"))
                            {
                                TableRow tr8 = new TableRow();
                                TableRow tr82 = new TableRow();
                                tc1 = new TableCell();
                                Label lblLotAttribute8 = new Label {
                                    Text = lotTemplate.LotAttr08Label,
                                    CssClass = "label"
                                };
                                tc1.Controls.Add(lblLotAttribute8);
                                tc2 = new TableCell();
                                Control ctrl8 = this.GetControlByTypeAndValue(lotTemplate.LotAttr08Type, lotTemplate.LotAttr08Value, lotTemplate.LotAttr08Mandatory);
                                ctrl8.ID = "ctrl8";
                                tc2.Controls.Add(ctrl8);
                                if (!string.IsNullOrEmpty(lotTemplate.LotAttr08Mandatory) && (lotTemplate.LotAttr08Mandatory == "Y"))
                                {
                                    Control ctrl80 = this.GetRequirField("ctrl8");
                                    ((RequiredFieldValidator) ctrl80).ErrorMessage = "请输入  " + lotTemplate.LotAttr08Label;
                                    tc2.Controls.Add(ctrl80);
                                    lblMustInput = new Label {
                                        Text = "*",
                                        ForeColor = Color.Red
                                    };
                                    tc1.Controls.Add(lblMustInput);
                                    if (!flage)
                                    {
                                        ((RequiredFieldValidator) ctrl80).Enabled = false;
                                        lblMustInput.Visible = false;
                                        lblLotAttribute8.ForeColor = Color.Red;
                                        if (lotTemplate.LotAttr08Type.ToUpper() == "OPTIONLIST")
                                        {
                                            ((DropDownList) ctrl8).Items.Insert(0, "");
                                        }
                                    }
                                }
                                Control ctr81 = this.GetCompareValidator("ctrl8", lotTemplate.LotAttr08Type);
                                if (ctr81 != null)
                                {
                                    tc2.Controls.Add(ctr81);
                                }
                                tr8.Cells.Add(tc1);
                                tr82.Cells.Add(tc2);
                                tb.Rows.Add(tr8);
                                tb.Rows.Add(tr82);
                                tr82.Width = Unit.Pixel(360);
                                controls.Add(ctrl8);
                            }
                            break;

                        case "LotAttribut09":
                            if (!string.IsNullOrEmpty(lotTemplate.LotAttr09Visible) && (lotTemplate.LotAttr09Visible == "Y"))
                            {
                                TableRow tr9 = new TableRow();
                                TableRow tr92 = new TableRow();
                                tc1 = new TableCell();
                                Label lblLotAttribute9 = new Label {
                                    Text = lotTemplate.LotAttr09Label,
                                    CssClass = "label"
                                };
                                tc1.Controls.Add(lblLotAttribute9);
                                tc2 = new TableCell();
                                Control ctrl9 = this.GetControlByTypeAndValue(lotTemplate.LotAttr09Type, lotTemplate.LotAttr09Value, lotTemplate.LotAttr09Mandatory);
                                ctrl9.ID = "ctrl9";
                                tc2.Controls.Add(ctrl9);
                                if (!string.IsNullOrEmpty(lotTemplate.LotAttr09Mandatory) && (lotTemplate.LotAttr09Mandatory == "Y"))
                                {
                                    Control ctrl90 = this.GetRequirField("ctrl9");
                                    ((RequiredFieldValidator) ctrl90).ErrorMessage = "请输入  " + lotTemplate.LotAttr09Label;
                                    tc2.Controls.Add(ctrl90);
                                    lblMustInput = new Label {
                                        Text = "*",
                                        ForeColor = Color.Red
                                    };
                                    tc1.Controls.Add(lblMustInput);
                                    if (!flage)
                                    {
                                        ((RequiredFieldValidator) ctrl90).Enabled = false;
                                        lblMustInput.Visible = false;
                                        lblLotAttribute9.ForeColor = Color.Red;
                                        if (lotTemplate.LotAttr09Type.ToUpper() == "OPTIONLIST")
                                        {
                                            ((DropDownList) ctrl9).Items.Insert(0, "");
                                            ((DropDownList) ctrl9).SelectedIndex = 1;
                                        }
                                    }
                                }
                                Control ctr91 = this.GetCompareValidator("ctrl9", lotTemplate.LotAttr09Type);
                                if (ctr91 != null)
                                {
                                    tc2.Controls.Add(ctr91);
                                }
                                tr9.Cells.Add(tc1);
                                tr92.Cells.Add(tc2);
                                tb.Rows.Add(tr9);
                                tb.Rows.Add(tr92);
                                tr92.Width = Unit.Pixel(360);
                                controls.Add(ctrl9);
                            }
                            break;

                        case "LotAttribut010":
                            if (!string.IsNullOrEmpty(lotTemplate.LotAttr10Visible) && (lotTemplate.LotAttr10Visible == "Y"))
                            {
                                TableRow tr10 = new TableRow();
                                TableRow tr102 = new TableRow();
                                tc1 = new TableCell();
                                Label lblLotAttribute10 = new Label {
                                    Text = lotTemplate.LotAttr10Label,
                                    CssClass = "label"
                                };
                                tc1.Controls.Add(lblLotAttribute10);
                                tc2 = new TableCell();
                                ctrl10 = this.GetControlByTypeAndValue(lotTemplate.LotAttr10Type, lotTemplate.LotAttr10Value, lotTemplate.LotAttr10Mandatory);
                                ctrl10.ID = "ctrl10";
                                tc2.Controls.Add(ctrl10);
                                if (!string.IsNullOrEmpty(lotTemplate.LotAttr10Mandatory) && (lotTemplate.LotAttr10Mandatory == "Y"))
                                {
                                    Control ctrl100 = this.GetRequirField("ctrl10");
                                    ((RequiredFieldValidator) ctrl100).ErrorMessage = "请输入  " + lotTemplate.LotAttr10Label;
                                    lblMustInput = new Label {
                                        Text = "*",
                                        ForeColor = Color.Red
                                    };
                                    tc1.Controls.Add(lblMustInput);
                                    tc2.Controls.Add(ctrl100);
                                    if (!flage)
                                    {
                                        ((RequiredFieldValidator) ctrl100).Enabled = false;
                                        lblMustInput.Visible = false;
                                        lblLotAttribute10.ForeColor = Color.Red;
                                        if (lotTemplate.LotAttr10Type.ToUpper() == "OPTIONLIST")
                                        {
                                            ((DropDownList) ctrl10).Items.Insert(0, "");
                                        }
                                    }
                                }
                                Control ctr101 = this.GetCompareValidator("ctrl10", lotTemplate.LotAttr10Type);
                                if (ctr101 != null)
                                {
                                    tc2.Controls.Add(ctr101);
                                }
                                tr10.Cells.Add(tc1);
                                tr102.Cells.Add(tc2);
                                tb.Rows.Add(tr10);
                                tb.Rows.Add(tr102);
                                tr102.Width = Unit.Pixel(360);
                                controls.Add(ctrl10);
                            }
                            break;

                        case "ProduceDate":
                            if (!string.IsNullOrEmpty(lotTemplate.ProduceDateVisible) && (lotTemplate.ProduceDateVisible == "Y"))
                            {
                                TableRow tr11 = new TableRow();
                                TableRow tr112 = new TableRow();
                                tc1 = new TableCell();
                                Label lblProductDate = new Label {
                                    Text = lotTemplate.ProduceDateLabel,
                                    CssClass = "label"
                                };
                                tc1.Controls.Add(lblProductDate);
                                tc2 = new TableCell();
                                TextBox txtProduct = new TextBox();
                                tc2.Controls.Add(txtProduct);
                                txtProduct.ID = "txtProduct";
                                txtProduct.CssClass = "textbox";
                                if ((skuInfo != null) && (skuInfo.ShelfLifeIndicator == "Y"))
                                {
                                    txtProduct.Attributes.Add("onBlur", string.Concat(new object[] { "ProduceDatePlanning('", contrlID, "',", skuInfo.DaysToExpire * 0x18, ")" }));
                                }
                                txtProduct.Enabled = this.Enabled;
                                System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image {
                                    ID = "imgProductDate",
                                    ImageUrl = "../Images/calendar.gif",
                                    CssClass = "img",
                                    AlternateText = "请选择日期",
                                    Visible = this.Enabled
                                };
                                temp = "setday(this," + contrlID.ToString() + "_" + txtProduct.ClientID.ToString() + ")";
                                img.Attributes.Add("onclick", temp);
                                tc2.Controls.Add(img);
                                if (!string.IsNullOrEmpty(lotTemplate.ProduceDateMandatory) && (lotTemplate.ProduceDateMandatory == "Y"))
                                {
                                    requ = this.GetRequirField("txtProduct");
                                    requ.ErrorMessage = "必须输入生产日期!";
                                    lblMustInput = new Label {
                                        Text = "*",
                                        ForeColor = Color.Red
                                    };
                                    tc1.Controls.Add(lblMustInput);
                                    comp = this.GetCompareValidator("txtProduct", "date");
                                    tc2.Controls.Add(requ);
                                    tc2.Controls.Add(comp);
                                    if (!flage)
                                    {
                                        requ.Enabled = false;
                                        lblMustInput.Visible = false;
                                        lblProductDate.ForeColor = Color.Red;
                                    }
                                }
                                tr11.Cells.Add(tc1);
                                tr112.Cells.Add(tc2);
                                tb.Rows.Add(tr11);
                                tb.Rows.Add(tr112);
                                tr112.Width = Unit.Pixel(360);
                                controls.Add(txtProduct);
                            }
                            break;

                        case "ExpiryDate":
                            if (!string.IsNullOrEmpty(lotTemplate.ExpiryDateVisible) && (lotTemplate.ExpiryDateVisible == "Y"))
                            {
                                tr12 = new TableRow();
                                TableRow tr122 = new TableRow();
                                tc1 = new TableCell();
                                Label lblExpiryDate = new Label {
                                    Text = lotTemplate.ExpiryDateLabel,
                                    CssClass = "label"
                                };
                                tc1.Controls.Add(lblExpiryDate);
                                tc2 = new TableCell();
                                TextBox txtExpiryDate = new TextBox();
                                tc2.Controls.Add(txtExpiryDate);
                                txtExpiryDate.ID = "txtExpiryDate";
                                txtExpiryDate.CssClass = "textbox";
                                if ((skuInfo != null) && (skuInfo.ShelfLifeIndicator == "Y"))
                                {
                                    txtExpiryDate.Attributes.Add("onBlur", string.Concat(new object[] { "ExpiryDatePlanning('", contrlID, "',", skuInfo.DaysToExpire * 0x18, ")" }));
                                }
                                txtExpiryDate.Enabled = this.Enabled;
                                System.Web.UI.WebControls.Image img2 = new System.Web.UI.WebControls.Image {
                                    ID = "imgExpiryDate",
                                    ImageUrl = "../Images/calendar.gif",
                                    CssClass = "img",
                                    AlternateText = "请选择日期",
                                    Visible = this.Enabled
                                };
                                temp = "setday(this," + contrlID.ToString() + "_" + txtExpiryDate.ClientID.ToString() + ")";
                                img2.Attributes.Add("onclick", temp);
                                tc2.Controls.Add(img2);
                                if (!string.IsNullOrEmpty(lotTemplate.ExpiryDateMandatory) && (lotTemplate.ExpiryDateMandatory == "Y"))
                                {
                                    requ = this.GetRequirField("txtExpiryDate");
                                    requ.ErrorMessage = "必须输入失效日期";
                                    lblMustInput = new Label {
                                        Text = "*",
                                        ForeColor = Color.Red
                                    };
                                    tc1.Controls.Add(lblMustInput);
                                    comp = this.GetCompareValidator("txtExpiryDate", "date");
                                    tc2.Controls.Add(requ);
                                    tc2.Controls.Add(comp);
                                    if (!flage)
                                    {
                                        requ.Enabled = false;
                                        lblMustInput.Visible = false;
                                        lblExpiryDate.ForeColor = Color.Red;
                                    }
                                }
                                tr12.Cells.Add(tc1);
                                tr122.Cells.Add(tc2);
                                tb.Rows.Add(tr12);
                                tb.Rows.Add(tr122);
                                tr122.Width = Unit.Pixel(360);
                                controls.Add(txtExpiryDate);
                            }
                            break;

                        case "ExternalLot":
                            if (!string.IsNullOrEmpty(lotTemplate.ExternalLotVisible) && (lotTemplate.ExternalLotVisible == "Y"))
                            {
                                TableRow tr13 = new TableRow();
                                TableRow tr132 = new TableRow();
                                tc1 = new TableCell();
                                Label lblExternalLot = new Label {
                                    Text = lotTemplate.ExternalLotLabel,
                                    CssClass = "label"
                                };
                                tc1.Controls.Add(lblExternalLot);
                                tc2 = new TableCell();
                                TextBox txtExternalLot = new TextBox();
                                tc2.Controls.Add(txtExternalLot);
                                txtExternalLot.ID = "txtExternalLot";
                                txtExternalLot.CssClass = "textbox";
                                txtExternalLot.Enabled = this.Enabled;
                                if (!string.IsNullOrEmpty(lotTemplate.ExternalLotMandatory) && (lotTemplate.ExternalLotMandatory == "Y"))
                                {
                                    requ = this.GetRequirField("txtExternalLot");
                                    requ.ErrorMessage = "必须输入外部批号";
                                    lblMustInput = new Label {
                                        Text = "*",
                                        ForeColor = Color.Red
                                    };
                                    comp = this.GetCompareValidator("txtExternalLot", "CHAR");
                                    tc2.Controls.Add(requ);
                                    tc2.Controls.Add(comp);
                                    tc1.Controls.Add(lblMustInput);
                                    if (!flage)
                                    {
                                        requ.Enabled = false;
                                        lblMustInput.Visible = false;
                                        lblExternalLot.ForeColor = Color.Red;
                                    }
                                }
                                tr13.Cells.Add(tc1);
                                tr132.Cells.Add(tc2);
                                tb.Rows.Add(tr13);
                                tb.Rows.Add(tr132);
                                tr132.Width = Unit.Pixel(360);
                                controls.Add(txtExternalLot);
                            }
                            break;
                    }
                }
                base.Session["LotAttributeControls"] = controls;
                if (tb.Rows.Count > 0)
                {
                    int columns = columnCount;
                    int ctrlsCount = tb.Rows.Count / 2;
                    int tableRowCount = Convert.ToInt32(Math.Ceiling((decimal) (Convert.ToDecimal(ctrlsCount) / Convert.ToDecimal(columns))));
                    Table tempTable = new Table {
                        CssClass = "tLotAttribute"
                    };
                    int index = 0;
                    for (i = 0; i < tableRowCount; i++)
                    {
                        TableRow tempTR1 = new TableRow();
                        TableRow tempTR2 = new TableRow();
                        int counter = 0;
                        for (int j = (index * 2) * columns; j < tb.Rows.Count; j++)
                        {
                            if ((counter / 2) != columns)
                            {
                                TableCell tempTC = new TableCell();
                                if ((j % 2) == 0)
                                {
                                    tempTC = tb.Rows[j].Cells[0];
                                    if (tempTC != null)
                                    {
                                        tempTR1.Cells.Add(tempTC);
                                    }
                                    else
                                    {
                                        tempTR1.Cells.Add(new TableCell());
                                    }
                                }
                                else
                                {
                                    tempTC = tb.Rows[j].Cells[0];
                                    if (tempTC != null)
                                    {
                                        tempTR2.Cells.Add(tempTC);
                                    }
                                    else
                                    {
                                        tempTR2.Cells.Add(new TableCell());
                                    }
                                }
                                counter++;
                            }
                            else
                            {
                                index++;
                                break;
                            }
                        }
                        tempTable.Rows.Add(tempTR1);
                        tempTable.Rows.Add(tempTR2);
                    }
                    this.test.Controls.Add(tempTable);
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack && !(string.IsNullOrEmpty(this.skuid) || string.IsNullOrEmpty(this.owerid)))
            {
                this.LoadData(this.skuid, this.owerid, this.controlID, true, this.columnCount);
            }
        }

        public int ColumnCount
        {
            get
            {
                return this.columnCount;
            }
            set
            {
                this.columnCount = value;
            }
        }

        public string ControlID
        {
            get
            {
                return this.controlID;
            }
            set
            {
                this.controlID = value;
            }
        }

        public bool Enabled
        {
            get
            {
                return this.enabled;
            }
            set
            {
                this.enabled = value;
            }
        }

        public string OwnerID
        {
            get
            {
                return this.owerid;
            }
            set
            {
                this.owerid = value;
            }
        }

        public bool ShelfLifeIndicator
        {
            get
            {
                return this.shelflifeIndicator;
            }
            set
            {
                this.shelflifeIndicator = value;
            }
        }

        public string SkuID
        {
            get
            {
                return this.skuid;
            }
            set
            {
                this.skuid = value;
            }
        }
    }
}

